//
//  YZMFeedbackViewController.m
//  YZMicroStock
//
//  Created by apple on 2018/3/5.
//  Copyright © 2018年 cqjr. All rights reserved.
//

#import "YZMFeedbackViewController.h"
#import "YZMConfigureService.h"
#import "MBProgressHUD+Utils.h"

@interface YZMFeedbackViewController ()
@property (weak, nonatomic) IBOutlet UITextView *feedbackTV;
@property (weak, nonatomic) IBOutlet UILabel *tipLB;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;

@end

@implementation YZMFeedbackViewController

- (id)init{
    
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
        self.navigationItem.title = @"意见反馈";
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.groupTableViewBackgroundColor;
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请输入反馈，我们将不断改进";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor grayColor];
    placeHolderLabel.font = _feedbackTV.font;
    [placeHolderLabel sizeToFit];
    [_feedbackTV addSubview:placeHolderLabel];

    [_feedbackTV setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(commit)];
}

- (void)commit {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[YZMTDConfigureService sharedService] fetchConfigureDataSuccess:^{
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if ([_feedbackTV.text isEqualToString:@""]) {
            [MBProgressHUD showMessage:@"您还未填写反馈意见"];
            return;
        }
        _feedbackTV.text = @"";
        _phoneTF.text = @"";
        [MBProgressHUD showMessage:@"反馈成功"];
    } failure:^(NSError *error) {
        [MBProgressHUD showMessage:@"无网络，请稍后再试"];
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [_feedbackTV resignFirstResponder];
    [_phoneTF resignFirstResponder];
}

@end
